{extend name="public/base"}

{block name="title"}
合伙人申请
{/block}

{block name="style"}
{css href="/static/wechat/css/certification.css" /}
<style type="text/css">
    .msg_panel{position:fixed;top:0px;left:100%;width:100%;height:100%;background:#fff;overflow:auto;z-index:99;}
    #picker, .g-lxdz>input
    ,.weui-input{width:75%;}
    .weui-select{width: 75%; font-size: .7rem; height: inherit; line-height: inherit;padding-left:0;}
</style>
{/block}

{block name="body"}
<form action="{:url('p_certification/certification')}" id="audit_form">
    <div class="pageControl orderDetails" style="padding-bottom: 1.5rem;">
        <div class="msui_nav msui_navTop" style="border-bottom: 1px solid #cccccc;">
            <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
            <h1 class="msui_navTop-title">合伙人认证</h1>
        </div>
        <span class="g-sfmsg">身份信息</span>
        <ul class="g-ul-ipt">
            <li class="g-li">
                <div class="g-leb-div"><label>姓名</label></div>
                <div class="g-ipt-div"><input placeholder="请输入您身份证上的的姓名" name="proposer" value="{$partner.proposer|default=''}" /></div>
            </li>
            <li class="g-li gsolid">
                <div class="g-leb-div"><label>身份证</label></div>
                <div class="g-ipt-div"><input placeholder="请输入您的身份证号" name="card_no"  value="{$partner.card_no|default=''}"/></div>
            </li>
        </ul>
        <span class="g-sfmsg">身份证照片</span>
        <!--上传身份证照片-->
        <div class="g-scsfz-div">
            <div class="scsfz">
                <i class="sczmsfz" {notempty name="partner.id_card_in_hand"} style="background: url('{$partner.id_card_in_hand}') no-repeat" {/notempty}>
                    <div class="weui-uploader__input-box scsfz3">
                        <input id="uploaderInput1" class="weui-uploader__input" type="file" accept="image/*"  file-attr="" />
                        <input type="hidden" name="id_card_in_hand" value="{$partner.id_card_in_hand|default=''}" />
                    </div>
                </i>
                <p>手持身份证正面照片</p>
            </div>

            <div class="scsfz">
                <i class="zmsfz" {notempty name="partner.id_card_front"} style="background: url('{$partner.id_card_front}') no-repeat" {/notempty}>
                    <div class="weui-uploader__input-box scsfz3">
                        <input id="uploaderInput2" class="weui-uploader__input" type="file" accept="image/*"  file-attr="" />
                        <input type="hidden" name="id_card_front" value="{$partner.id_card_front|default=''}" />
                    </div>
                </i>
                <p>身份证正面照片</p>
            </div>

            <div class="scsfz" style="margin-top: -1rem;">
                <i class="sfzfm" {notempty name="partner.id_card_verso"} style="background: url('{$partner.id_card_verso}') no-repeat" {/notempty}>
                    <div class="weui-uploader__input-box scsfz3">
                        <input id="uploaderInput3" class="weui-uploader__input" type="file" accept="image/*"  file-attr="" />
                        <input type="hidden" name="id_card_verso" value="{$partner.id_card_verso|default=''}" />
                    </div>
                </i>
                <p>身份证反面照片</p>
            </div>
        </div>
        <a id="s_next_but_no" class="u-sub audit_send_next" style="background:#999;color: #ffffff;" href="javascript:;" >下一步</a>
        <a id="s_next_but" class="u-sub audit_send_next" style="display:none;color: #ffffff;" href="javascript:;" onclick="$('#s_zizhi_box').animate({'left':'0'});">下一步</a>

    </div>


    <div id="s_zizhi_box" class="msg_panel">
        <div class="pageControl startShop bg-f8">
            <div class="msui_nav msui_navTop" style="border-bottom: 1px solid #cccccc;">
                <a class="msui_navTop-back" href="javascript:;" onclick="$('#s_zizhi_box').animate({'left':'100%'});"><i class="micon-back"></i></a>
                <h1 class="msui_navTop-title">合伙人认证</h1>
            </div>


            <!--意向区域-->
            <span class="g-sfmsg">意向区域</span>
            <div class="weui-cells">
                <i class="weui-cell weui-cell_access"style="padding: 15px;">
                    <div class="weui-cell__bd">
                        <p class="fs07">意向等级</p>
                        <input class="weui-input" type="text" id='picker' name="level" placeholder="请选择" value="省"/>
                    </div>
                    <div class="weui-cell__ft">
                    </div>
                </i>
                <a class="weui-cell weui-cell_access" href="javascript:;" style="padding: 15px;">
                    <div class="weui-cell__bd">
                        <p class="fs07">意向区域</p>
                        <input class="weui-input" id="start" type="text" placeholder="省、市、区/县">
                        <input type="hidden" name="duty_area">
                    </div>
                    <div class="weui-cell__ft">
                    </div>
                </a>
            </div>
            <div class="g-lxdz">
                <label>联系电话</label>
                <input class="weui-input" id="mobile" name="mobile" type="tel" placeholder='请输入联系电话'  value="{$partner.mobile ? $partner.mobile : $Think.session.phone}" />
            </div>
            <!--联系地址-->
            <!--<div class="g-lxdz">-->
                <!--<label>联系地址</label>-->
                <!--<input  class="weui-input" id="contact_address" type="text"  placeholder="省、市、区/县"  data-code="{$partner.area|default=''}" data-codes=""/>-->
                <!--<input type="hidden" name="contact_address">-->
            <!--</div>-->
            <!--<div class="g-lxdz">-->
                <!--<label>选择街道</label>-->
                <!--<select class="weui-select" name="street" >-->
                    <!--<option>请选择</option>-->
                <!--</select>-->
            <!--</div>-->
            <!--<div class="g-lxdz">-->
                <!--<label>详情地址</label>-->
                <!--<input  class="weui-input" id="address" name="address" type="text" placeholder='请输入详情地址' value="{$partner.address|default=''}"/>-->
            <!--</div>-->
            <input type="hidden" name="province" value="" />
            <input type="hidden" name="city" value="" />
            <input type="hidden" name="area" value="" />
            <input type="hidden" name="street" value="" />
            <!--联系地址-->
            <div class="g-lxdz">
                <label>联系地址</label>
                <input  class="weui-input" id="contact_address" type="text" readonly />
            </div>
            <div class="g-lxdz">
                <label>街道</label>
                <input  class="weui-input" id="street" type="text" readonly />
            </div>

            <div class="weui-cell weui-cell_access shop_site">
                <div class="weui-cell__hd">
                    <label class="weui-label cl-3333">详细地址</label>
                </div>
                <div class="weui-cell__bd">
                    <input name="address" type="text" class="weui-input" placeholder="请输入详细地址" value="{$partner.address|default=''}" />
                    <img id="box_map_open" src="/static/wechat/images/shop_logo_07.jpg" alt="" style="width: 2rem;" />
                </div>
            </div>
            <a id="s_btn_submit_no" class="u-sub audit_send" style="background:#999;color: #ffffff;" href="javascript:;">提交审核</a>
            <a id="s_btn_submit" class="u-sub audit_send" style="display:none;color: #ffffff;" href="javascript:;">提交审核</a>
            <input name="lat" type="hidden" value="{$partner.lat|default=''}" />
            <input name="lon" type="hidden" value="{$partner.lon|default=''}"  />
            <input name="id" type="hidden" value="{$partner.id|default=''}" />


        </div>
    </div>


</form>
<!-- loading toast -->
<div id="loadingToast" style="display:none;">
    <div class="weui-mask_transparent"></div>
    <div class="weui-toast" style="opacity: 1; visibility: visible;">
        <i class="weui-loading weui-icon_toast"></i>
        <p class="weui-toast__content">加载中...</p>
    </div>
</div>
<!--map-->
<div id="box_map" style="display:none;position:fixed;top:0;left:0;z-index:9999;width:100%;height:100%;">
    <div id="container" tabindex="0" style="display:block;position:absolute;top:0;left:0;z-index:9999;width:100%;height:100%;"></div>
    <img id="box_map_close" src="/static/wechat/images/radio.png" style="position:absolute;right:10px;bottom:10px;z-index:9999;width: 2rem;height: 2rem;" />
    <img src="http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png" style="display:block;position:absolute;top:50%;left:50%;z-index:9999;width:19px;height:31px;margin:-31px 0 0 -9px;" />
</div>
{/block}
{block name="javascript"}
<script>
    $(function () {
//        $("#contact_address").val("{$partner.r_province|default=''} {$partner.r_city|default=''} {$partner.r_area|default=''}").data('codes', "{$partner.province|default=0},{$partner.city|default=0},{$partner.area|default=0}");
//        $("input[name='contact_address']").val("{$partner.province|default=0},{$partner.city|default=0},{$partner.area|default=0}");

        $("#start").val("{$partner.dap_province|default=''} {$partner.dac_city|default=''} {$partner.dae_area|default=''}").attr('data-codes', "{$partner.da_province|default=0},{$partner.da_city|default=0},{$partner.da_area|default=0}");
        $("input[name='duty_area']").val("{$partner.da_province|default=0},{$partner.da_city|default=0},{$partner.da_area|default=0}");

        var levels = ['', '省', '市', '区/县'];
        var level = {$partner.level|default=1};
        $("input[name='level']").val(levels[level]);
    });
</script>

{js href="/static/wechat/jquery_weui/js/data-picker1.js" /}
{js href="/static/wechat/jquery_weui/js/city-picker.js" /}
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=9a8d0d7e358d9d80f7f61a1989ba35a0"></script>
<script>
var s_submit_but_check = window.setInterval(function(){
    if(
            $('input[name="card_no"]').val().length<18
            || $('input[name="proposer"]').val().length<2
            || $('input[name="id_card_in_hand"]').val().length<15
            || $('input[name="id_card_front"]').val().length<15
            || $('input[name="id_card_verso"]').val().length<15
    ){
        $('a#s_next_but_no').show();
        $('a#s_next_but').hide();
    }else{
        $('a#s_next_but_no').hide();
        $('a#s_next_but').show();
    }

    if(
            $("input[name='mobile']").val().length<6
            || $('input[name="level"]').val()==""
            || $('input[name="duty_area"]').val()==""
            || $('input[name="contact_address"]').val()==""
            || $('select[name="street"]').val()==""
            || $('input[name="address"]').val()==""
    ){
        $('a#s_btn_submit_no').show();
        $('a#s_btn_submit').hide();
    }else{
        $('a#s_btn_submit_no').hide();
        $('a#s_btn_submit').show();
    }
},800);

//初始化地图
mapObj = new AMap.Map('container',{
    resizeEnable: true,
    zoom: 15,
    //zoomEnable: false,	//禁止放大缩小
    //dragEnable: false,	//禁止拖动
    mapStyle:'fresh'
});

if($('input[name="id"]').val() == 0) {
    //监控用户位置
    mapObj.plugin('AMap.Geolocation', function () {
        geolocation = new AMap.Geolocation({
            enableHighAccuracy: true,//是否使用高精度定位，默认:true
            timeout: 30000,          //超过30秒后停止定位，默认：无穷大
            maximumAge: 0,           //定位结果缓存0毫秒，默认：0
            convert: true,           //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
            showButton: true,        //显示定位按钮，默认：true
            buttonPosition: 'LB',    //定位按钮停靠位置，默认：'LB'，左下角
            buttonOffset: new AMap.Pixel(10, 10),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
            showMarker: true,        //定位成功后在定位到的位置显示点标记，默认：true
            showCircle: false,        //定位成功后用圆圈表示定位精度范围，默认：true
            panToLocation: true,     //定位成功后将定位到的位置作为地图中心点，默认：true
            zoomToAccuracy: true,      //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            extensions: 'base'
        });
        //markerOptions: window.my_dingdan,
        mapObj.addControl(geolocation);//开始监控
        AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息//onComplete
        AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
        $(".amap-geo").trigger("click");
    });
}else{
    if($('input[name="lat"]').val()!="" && $('input[name="lon"]').val()!=""){
        mapObj.setCenter(new AMap.LngLat($('input[name="lon"]').val(),$('input[name="lat"]').val()))
        map_get_address();
    }
}

//开始拖拽地图时
mapObj.on("dragstart", function(){
    window.clearTimeout(window.dragTime);
});
//拖拽地图过程中
mapObj.on("dragging", function(){
    //window.clearTimeout(window.dragTime);

});
//停止拖拽地图时
mapObj.on("dragend", function(){
    window.dragTime = setTimeout(function() {
        var tmp = mapObj.getCenter();console.log(tmp);
        $('input[name="lat"]').val(tmp.lat);
        $('input[name="lon"]').val(tmp.lng);
        map_get_address();
    },666);
});


$("#picker").picker({
    title: "请选择您的意向等级",
    cols: [
        {
            textAlign: 'center',
            values: ['省', '市', '区/县']
        }
    ]
});

$("#start").cityPicker({
    title: "选择意向区域",
    onChange: function (picker, values, displayValues) {
        var _picker = $("#picker").val();
        switch (_picker) {
            case '省':
                displayValues.splice(1,2);
                break;
            case '市':
                displayValues.splice(2,1);
                break;
            default:
                break;
        }
        $("#start").val(displayValues.join(" "));
    }
});

//$("#contact_address").cityPicker({
//    title: "选择联系地址",
//    onChange: function (picker, values, displayValues) {
//    }
//});

//var _is_contact_address = true;
//$("#contact_address").change(function () {
//    _is_contact_address=true;
//});
//get_street();
//$(document).on('click', ".picker-button:first", function () {
//    get_street()
//});
//
//function get_street() {
//    if (_is_contact_address) {
//        $('.weui-toast__content').html('获取数据...');
//        $('#loadingToast').fadeIn();
//        var area = $("#contact_address").attr('data-code');
//        var street = '{$partner.street|default=0}';
//        if (!area) {
//            $('#loadingToast').fadeOut();
//            return false;
//        }
//        $.get("{:url('wechat/base/get_street')}", {area: area}, function (msg) {
//            $('#loadingToast').fadeOut();
//            var html = [];
//            var data = msg.data;
//            var len = data.length;
//            html.push("<option value=''>请选择</option>");
//            for (var i = 0; i < len; i++) {
//                if (data[i].region_id == street)
//                    html.push("<option value='"+ data[i].region_id +"' selected>"+ data[i].region_name +"</option>");
//                else
//                    html.push("<option value='"+ data[i].region_id +"'>"+ data[i].region_name +"</option>");
//            }
//            $("select[name='street']").html(html.join(''));
//        }, 'json');
//    }
//    _is_contact_address = false;
//}

function map_get_address(){
    $('#loadingToast').fadeIn();
    $.ajax({
        type:"get",
        cache:false,
        dataType:"json",
        url:"{:url('Base/map_get_address')}?lat="+$('input[name="lat"]').val()+"&lng="+$('input[name="lon"]').val(),
        error:function(s){
            $('#loadingToast').fadeOut();
        },
        success:function(d){
            $('#loadingToast').fadeOut();
            window.console.log(d);
            if(d.status==1){
                var address_array = d.regeocode.addressComponent;
                $('input[name="province"]').val(address_array.province);
                $('input[name="city"]').val(address_array.city);
                $('input[name="area"]').val(address_array.district);
                $('input[name="street"]').val(address_array.township);
                var tmpAddress = d.regeocode.formatted_address;//.split(d.regeocode.addressComponent.township)[1];
                $('#contact_address').val(address_array.province + address_array.city + address_array.district);
                $('#street').val(address_array.township);

                var newstr=tmpAddress.replace(address_array.province + address_array.city + address_array.district + address_array.township, "");
                $('input[name="address"]').val(newstr);
            }else{
                alert(d.info);
            }
        }
    });
}


$("input[type='file']").change(function () {
    upload_id_card($(this));
});

//  提交申请
$(".audit_send").click(function (e) {
    //alert($('input[name="lat"]').val() + '++' + $('input[name="lon"]').val() );
    $('#loadingToast').fadeIn();
    $('.weui-toast__content').html('正在提交...');
    e.preventDefault();
    var f = $("#audit_form");
    //alert(f.serialize());
    $("input[name='duty_area']").val($('#start').attr('data-codes'));
//    $("input[name='contact_address']").val($('#contact_address').attr('data-codes'));
    $.ajax({
        type : 'POST',
        url : f.attr('action'),
        data : f.serialize(),
        dataType : 'json',
        success : function (msg) {
            $('#loadingToast').fadeOut();
            if (msg.code == 200) {
                $.alert('提交成功');
                setTimeout(function () {
                    window.location.href="{:url('audit_status', ['status' => 1])}";
                }, 1000);
            } else {
                var code = msg.code;
                $.alert(error_code[code]);
            }
        }
    });
});



//处理定位信息
function onComplete(data){
    //point	Point	坐标点。
    //accuracy	Number	定位精确程度，单位为米。
    //alert(data.info + '===' + data.position.L + '===' + data.position.I)
    if(data.info=="SUCCESS"){
        if ( $('input[name="lat"]').val() == '')
            $('input[name="lat"]').val(data.position.lat);

        if ($('input[name="lon"]').val() == '')
            $('input[name="lon"]').val(data.position.lng);

        map_get_address();
    }
}

//处理定位出错信息
//处理定位出错信息
function onError(e){
    $.confirm("没有获取到您的位置信息<br>是否重新获取?","位置信息",function(){
        window.location.reload();
    },function(){
        return false;
    });
}

$(function () {
    //地图选择定位经纬度
    $('#box_map_open').click(function(){
        $('#box_map').css("display","block");
        $('#box_map').css("height",$(window).height());
    });
    $('#box_map_close').click(function(){
        $('#box_map').css("display","none");
    });

    $('#contact_address').click(function () {
        $('#box_map').css("display","block");
        $('#box_map').css("height",$(window).height());
    });
    $('#street').click(function () {
        $('#box_map').css("display","block");
        $('#box_map').css("height",$(window).height());
    });
});
</script>
{/block}